

chars = [
    (b'\xc2\x95', b'\xc2\xb7')
]

old_files = ('/home/yehun/Downloads/cuyoo_e_4.en', '/home/yehun/Downloads/cuyoo_c_4.cn')
new_files = ('/home/yehun/cuyoo_e_4.en', '/home/yehun/cuyoo_c_4.cn')

line_no_list = []
with open(old_files[0], encoding='utf-8') as f:
    for (index, line) in enumerate(f):
        line = line.replace('\n', '')
        if line.find('??') > -1 or line.find('?') > -1:
            line_no_list.append(index)


with open(old_files[1], encoding='utf-8') as f:
    for (index, line) in enumerate(f):
        line = line.replace('\n', '')
        if line.find('??') > -1 or line.find('?') > -1:
            line_no_list.append(index)

line_no_list = list(set(line_no_list))
line_no_list.sort()


print(len(line_no_list))
print(line_no_list)

en_lines, cn_lines = [], []
with open(old_files[0], encoding='utf-8') as f:
    for (index, line) in enumerate(f):
        if index in line_no_list:
            continue
        line = line.replace('\n', '')
        en_lines.append(line)

with open(old_files[1], encoding='utf-8') as f:
    for (index, line) in enumerate(f):
        if index in line_no_list:
            continue
        line = line.replace('\n', '')
        cn_lines.append(line)

with open(new_files[0], encoding='utf-8', mode='w+') as ff:
    content = '\n'.join(en_lines)
    content = content.encode().replace(b'\xc2\x95', b'\xc2\xb7').decode()
    ff.write(content)

with open(new_files[1], encoding='utf-8', mode='w+') as ff:
    content = '\n'.join(cn_lines)
    content = content.encode().replace(b'\xc2\x95', b'\xc2\xb7').decode()
    ff.write(content)

